package edu.whu.tao.util;

import com.xiaoleilu.hutool.util.CollectionUtil;

import edu.whu.tao.annotation.Logical;


public class AuthUtils {
	
	public static boolean isPermit(String[] permitRoles, Logical logical, String[] hasRoles) {
		boolean isPermit = false;
		if (hasRoles == null) {
			return isPermit;
		}
		if (logical == Logical.AND) {
			for (String role : permitRoles) {
				if (!CollectionUtil.contains(hasRoles, role)) {
					isPermit = false;
					return isPermit;
				}
			}
			isPermit = true;
		} else if (logical == Logical.OR) {
			for (String role : permitRoles) {
				if (CollectionUtil.contains(hasRoles, role)) {
					isPermit = true;
					return isPermit;
				}
			}
			isPermit = false;
		}
		return isPermit;
	}

	public static boolean isPermit(String[] permitRoles, String[] hasRoles) {
		return isPermit(permitRoles, Logical.OR, hasRoles);
	}
}
